package com.eshop.modules.product.service.mapper;

import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;
import com.eshop.modules.product.domain.StoreProductAttrValue;
import com.eshop.common.mapper.CoreMapper;

@Repository
public interface StoreProductAttrValueMapper extends CoreMapper<StoreProductAttrValue>
{
    @Update({ "update store_product_attr_value set stock=stock+#{num}, sales=sales-#{num} where product_id=#{productId} and `unique`=#{unique}" })
    int incStockDecSales(@Param("num") final Integer num, @Param("productId") final Long productId, @Param("unique") final String unique);
    
    @Update({ "update store_product_attr_value set stock=stock+#{num}, pink_stock=pink_stock+#{num}, sales=sales-#{num} where product_id=#{productId} and `unique`=#{unique}" })
    int incCombinationStockDecSales(@Param("num") final Integer num, @Param("productId") final Long productId, @Param("unique") final String unique);
    
    @Update({ "update store_product_attr_value set stock=stock+#{num},seckill_stock=seckill_stock+#{num}, sales=sales-#{num} where product_id=#{productId} and `unique`=#{unique}" })
    int incSeckillStockDecSales(@Param("num") final Integer num, @Param("productId") final Long productId, @Param("unique") final String unique);
    
    @Update({ "update store_product_attr_value set stock=stock-#{num}, sales=sales+#{num} where product_id=#{productId} and `unique`=#{unique} and stock >= #{num}" })
    int decStockIncSales(@Param("num") final Integer num, @Param("productId") final Long productId, @Param("unique") final String unique);
    
    @Update({ "update store_product_attr_value set stock=stock-#{num}, pink_stock=pink_stock-#{num} ,sales=sales+#{num} where product_id=#{productId} and `unique`=#{unique} and stock >= #{num} and pink_stock>=#{num}" })
    int decCombinationStockIncSales(@Param("num") final Integer num, @Param("productId") final Long productId, @Param("unique") final String unique);
    
    @Update({ "update store_product_attr_value set stock=stock-#{num}, seckill_stock=seckill_stock-#{num},sales=sales+#{num} where product_id=#{productId} and `unique`=#{unique} and stock >= #{num} and seckill_stock>=#{num}" })
    int decSeckillStockIncSales(@Param("num") final Integer num, @Param("productId") final Long productId, @Param("unique") final String unique);
}
